﻿using MrPP.iot.Guide;
using System;
using UnityEngine;

namespace MrPP.SerriedCabinet
{
    public class CellDraw : MonoBehaviour
    {
        public GameObject clicked;

      
        public GameObject edging;
        public GameObject core;
        public GameObject ui;
        public CellHighlightUI highlight;
        public CellShelveUI shelve;
        public CellCheckUI check;
        public GuideTarget target;

        public Action<BoxLocation> callback;

        void Start() {
            close();
        }
        internal void close()
        {
           
            edging.gameObject.SetActive(false);
            ui.gameObject.SetActive(false);
            core.gameObject.SetActive(false);
            highlight.gameObject.SetActive(false);
            shelve.gameObject.SetActive(false);
            check.gameObject.SetActive(false);
        }
        public void onClicked(Location location) {
            //Debug.LogError("AAA");
            callback?.Invoke(location.location);
        }
        internal void show(bool eshow, Box.Type type, Action<BoxLocation> callback = null)
        {
            close();
            edging.gameObject.SetActive(eshow);
            if (type == Box.Type.None)
            {
                this.ui.SetActive(false);
            }
            else {

                this.ui.SetActive(true);

                if (type == Box.Type.Left)
                {
                   ui.transform.localEulerAngles = new Vector3(0, 0, 0);
                }
                else
                {

                    ui.transform.localEulerAngles = new Vector3(0, 180, 0);
                }
            }

            if (callback == null)
            {
               
                core.gameObject.SetActive(false);
            }
            else {
                core.gameObject.SetActive(true);
            }
        }

        internal void setHighlight(string text, BoxLocation location)
        {

            highlight._text.text = text;
            highlight._position.text = location.ToString();
            highlight.gameObject.SetActive(true);

        }
        /*
            [SerializeField]
        private TMPro.TextMeshProUGUI _all;
        [SerializeField]
        private TextMeshProUGUI _left;
        [SerializeField]
        private TextMeshProUGUI _goods;
        [SerializeField]
        private TextMeshProUGUI _check;


        [SerializeField]
        private Slider _slider;
             
             */
        internal void setCheck(string all, string left, string cck, BoxLocation location, float value)
        {

            check._all.text = all;
            check._left.text = left;
            check._check.text = cck;
            check._slider.value = value;
            check.gameObject.SetActive(true);
        }
        internal void setShelve(string text, BoxLocation location)
        {

            shelve._text.text = text;
            shelve._position.text = location.ToString();
            shelve.gameObject.SetActive(true);
        }
    }
}